package com.waterworld.watch.location.manager;

import android.content.Context;
import android.util.Log;

import com.waterworld.watch.common.application.MyApplication;
import com.waterworld.watch.common.bean.LocationBean;
import com.waterworld.watch.common.net.BaseObserverListener;
import com.waterworld.watch.common.net.BaseResultBean;
import com.waterworld.watch.common.net.NetManager;
import com.waterworld.watch.location.interfaces.ILocationManager;
import com.waterworld.watch.login.manager.LoginManager;

import rx.Subscriber;

/**
 * Created by nhuan
 * Time:2019/3/10.
 */

public class LocationManager implements ILocationManager {

    private static LocationManager mInstance;
    private Context mContext;

    public static LocationManager getInstance(){
        if(mInstance == null){
            synchronized (LoginManager.class){
                if(mInstance == null){
                    mInstance = new LocationManager(MyApplication.getContext());
                }
            }
        }
        return mInstance;
    }

    private LocationManager(Context context){
        super();
        this.mContext = context;
    }
    @Override
    public void getLocation(BaseObserverListener baseObserverListener) {
        NetManager.getInstance().getLocation(new Subscriber<BaseResultBean<LocationBean>>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean<LocationBean> baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void getLastLocation(BaseObserverListener baseObserverListener) {
        NetManager.getInstance().getLastLocation(new Subscriber<BaseResultBean<LocationBean>>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean<LocationBean> baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void getSecurityFence(Integer pageNum, Integer pageSize, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().getSecurityFence(pageNum, pageSize, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void addSecurityFence(String name, Integer remindWay, Integer fenceRange, String remindTime, String remindDays, String fenceLat, String fenceLng, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().addSecurityFence(name, remindWay, fenceRange, remindTime, remindDays, fenceLat, fenceLng, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void updateSecurityFence(Integer id, String name, Integer remindWay, Integer fenceRange, String remindTime, String remindDays, String fenceLat, String fenceLng, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().updateSecurityFence(id, name, remindWay, fenceRange, remindTime, remindDays, fenceLat, fenceLng, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void isEnableSecurityFence(Integer id, Boolean isEnable, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().isEnableSecurityFence(id, isEnable, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void deleteSecurityFence(Integer id, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().deleteSecurityFence(id, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }

    @Override
    public void getTrack(String date, BaseObserverListener baseObserverListener) {
        NetManager.getInstance().getTrack(date, new Subscriber<BaseResultBean>() {
            @Override
            public void onCompleted() {
                baseObserverListener.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                baseObserverListener.onError(e);
            }

            @Override
            public void onNext(BaseResultBean baseResultBean) {
                baseObserverListener.onNext(baseResultBean);
            }
        });
    }
}
